package cn.edu.lingnan.mapper;


import cn.edu.lingnan.user.dtos.ClassQueryDTO;
import cn.edu.lingnan.user.dtos.ClassStudentQueryDTO;
import cn.edu.lingnan.user.pojos.Class;
import cn.edu.lingnan.user.vos.ClassVO;
import cn.edu.lingnan.user.vos.UserVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ClassMapper {

    Page<ClassVO> getClassList(ClassQueryDTO queryDTO);

    @Select("SELECT * FROM tb_class WHERE id = #{id}")
    Class getClassInfo(Integer id);

    @Insert("INSERT INTO tb_class(name, grade,academy, create_time, update_time) " +
            " VALUES (#{name}, #{grade},#{academy},now(),now())")
    void addClass(Class classInfo);

    @Update("UPDATE tb_class SET name = #{name}, grade = #{grade},academy=#{academy}, update_time = now() WHERE id = #{id}")
    void updateClass(Class classInfo);

    @Delete("delete from tb_class where id = #{id}")
    boolean deleteClassById(Integer id);

    @Delete("delete from tb_student_class where class_id = #{id}")
    boolean deleteClassUserById(Integer id);

    @Select("SELECT student_id FROM tb_student_class WHERE class_id = #{id}")
    List<Integer> getStudentIdListByClassId(Integer id);

    Page<UserVO> getStudentList(ClassStudentQueryDTO queryDTO,Integer id);

    @Delete("delete from tb_student_class where student_id = #{studentId} and class_id = #{classId}")
    boolean removeStudent(Integer studentId, Integer classId);

    @Select("SELECT count(*) FROM tb_student_class WHERE class_id = #{id}")
    Integer getStudentCountByClassId(Integer id);
}
